<template>
  <view class="menuContent" v-if="params">
    <view class="menuBox">
      <view
        class="item"
        :class="[getClass(item.id, choose)]"
        v-for="item of params.items"
        :key="item.id"
        @click="change('choose', item.id)"
      >
        {{ item.name }}
        <view class="line"></view>
      </view>
    </view>

    <view class="tag">
      <view
        class="item"
        v-for="item of params.tags"
        :key="item.id"
        :class="[getClass(item.id, type)]"
        @click="change('type', item.id)"
      >
        {{ item.name + " " + item.num }}</view
      >
    </view>
  </view>
</template>

<script>
export default {
  props: {
    type: {
      type: String,
      default: "",
    },

    choose: {
      type: String,
      default: "",
    },

    params: {
      type: Object,
      default: null,
    },
  },

  computed: {
    getClass() {
      return (val, active) => {
        return val === active ? "on" : "";
      };
    },
  },

  data() {
    return {};
  },

  methods: {
    change(key, value) {
      if (this[key] === value) {
        return;
      }

      this.$emit("change", key, value);
    },
  },
};
</script>

<style lang="scss" scoped>
.menuBox {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid #f2f2f2;
  background: #fff;

  .item {
    position: relative;
    padding: 0 52rpx;
    height: 86rpx;
    line-height: 86rpx;
    color: #8c8c8c;
    font-size: 28rpx;
    font-weight: bold;

    .line {
      position: absolute;
      left: 52rpx;
      bottom: 0;
      right: 52rpx;
      height: 4rpx;
      background: #262626;
      transition: 0.3s all;
      opacity: 0;
    }

    &.on {
      color: #262626;

      .line {
        opacity: 1;
      }
    }
  }
}

.tag {
  display: flex;
  padding: 16rpx 30rpx;
  background: #fff;

  .item {
    margin-right: 4rpx;
    padding: 6rpx 18rpx;
    font-size: 24rpx;
    color: #262626;
    border-radius: 8rpx;
    transition: 0.3s all;

    &.on {
      background: #f8f8f8;
    }
  }
}
</style>
